package com.qingmi.farmer.data.repository.api;


import com.qingmi.farmer.data.model.Buyer;
import com.qingmi.farmer.data.model.GrainDemand;
import com.qingmi.farmer.data.model.GrainLevel;
import com.qingmi.farmer.data.model.GrainOrder;
import com.qingmi.farmer.data.model.GrainType;
import com.wjjun.base.data.net.HTTPSService;
import com.wjjun.base.data.preference.UserPreference;
import com.qingmi.farmer.data.request.GetGrainDemandListReq;
import com.qingmi.farmer.data.request.GetGrainOrderReq;
import com.wjjun.basemvpvm.data.net.HttpApiManager;
import com.wjjun.basemvpvm.data.net.filter.BaseResponseFilter;
import com.wjjun.basemvpvm.data.repository.BaseApiRepository;
import com.wjjun.basemvpvm.data.request.SimpleRequest;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * 粮食模块
 * Created by 67535 on 2018/5/23.
 */
public class GrainApiRepository extends BaseApiRepository {


    private UserPreference userPreference;


    @Inject
    public GrainApiRepository(HttpApiManager httpApiManager, BaseResponseFilter filter, UserPreference userPreference) {
        super(httpApiManager, filter);
        this.userPreference = userPreference;
    }


    /**
     * 获取粮食类型
     */
    public Observable<List<GrainType>> getGrainTypeList() {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGrainTypeList(userPreference.getToken()));
    }


    /**
     * 获取粮食等级
     */
    public Observable<List<GrainLevel>> getGrainLevelList() {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGrainLevelList(userPreference.getToken()));
    }


    /**
     * 获取收购商列表
     */
    public Observable<List<Buyer>> getBuyerList() {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getBuyerList());
    }

    /**
     * 获取农户粮食订单列表
     */
    public Observable<List<GrainOrder>> getGrainOrderList(GetGrainOrderReq req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGrainOrderList(req.toMap(), userPreference.getToken()));
    }

    /**
     * 获取农户粮食订单详情
     */
    public Observable<GrainOrder> getGrainOrderDetail(SimpleRequest req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGrainOrderDetail(req.getId(), userPreference.getToken()));
    }

    /**
     * 收购列表
     */
    public Observable<List<GrainDemand>> getGrainDemandList(GetGrainDemandListReq req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGrainDemandList(req.toMap(), userPreference.getToken()));
    }


    /**
     * 收购详情
     */
    public Observable<GrainDemand> getGrainDemandDetail(SimpleRequest req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGrainDemandDetail(req.getId(), userPreference.getToken()));
    }

}
